package com.yurun.orgstudentmodule.service.Impl;

import com.yurun.commonapi.api.CommonResult;
import com.yurun.commonapi.aspect.PermissionAnnotation;
import com.yurun.commonapi.pojo.GroupTrainingPlanSummaryWeek202112;
import com.yurun.commonapi.pojo.StudentDocument;
import com.yurun.commonapi.pojo.StudentTrainingTable;
import com.yurun.orgstudentmodule.mapper.*;
import com.yurun.orgstudentmodule.service.TrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.*;

@Service
public class TrainingServiceImpl implements TrainingService {

    @Autowired
    private AloneClassMonthPlanAndSummaryMapper aloneClassMonthPlanAndSummaryMapper;

    @Autowired
    private AloneClassMonthTeachingSummaryMapper aloneClassMonthTeachingSummaryMapper;

    @Autowired
    private AloneClassMonthTeachingScheduleMapper aloneClassMonthTeachingScheduleMapper;

    @Autowired
    private AloneClassRecordMapper aloneClassRecordMapper;

    @Autowired
    private AloneClassSeasonPlanAndSummaryMapper aloneClassSeasonPlanAndSummaryMapper;

    @Autowired
    private AloneClassSummaryPhaseMapper aloneClassSummaryPhaseMapper;

    @Autowired
    private AloneClassWeekFeedbackMapper aloneClassWeekFeedbackMapper;

    @Autowired
    private AloneClassWeekStudyReportMapper aloneClassWeekStudyReportMapper;

    @Autowired
    private AloneClassWeekTeachingScheduleMapper aloneClassWeekTeachingScheduleMapper;

    @Autowired
    private AloneClassWeekTeachingSummaryMapper aloneClassWeekTeachingSummaryMapper;

    @Autowired
    private GroupTrainingPlanSummaryMonthMapper groupTrainingPlanSummaryMonthMapper;

    @Autowired
    private GroupTrainingPlanSummaryPhaseMapper groupTrainingPlanSummaryPhaseMapper;

    @Autowired
    private GroupTrainingPlanSummaryWeekMapper groupTrainingPlanSummaryWeekMapper;

    @Autowired
    private PerceptionTrainningMapper perceptionTrainningMapper;

    @Autowired
    private StudentAssessmentProgramMapper studentAssessmentProgramMapper;

    @Autowired
    private TrainingPerformanceFeedbackMonthMapper trainingPerformanceFeedbackMonthMapper;

    @Autowired
    private TrainingPerformanceFeedbackQuarterMapper trainingPerformanceFeedbackQuarterMapper;

    @Autowired
    private TrainingPerformanceFeedbackWeekMapper trainingPerformanceFeedbackWeekMapper;

    @Autowired
    private AloneClassSummaryPhase202111Mapper  aloneClassSummaryPhase202111Mapper;

    @Autowired
    private AnnualSummary202111Mapper annualSummary202111Mapper;

    @Autowired
    private GroupTrainingPlanSummaryMonth202111Mapper groupTrainingPlanSummaryMonth202111Mapper;

    @Autowired
    private GroupTrainingPlanSummaryWeek202111Mapper groupTrainingPlanSummaryWeek202111Mapper;

    @Autowired
    private PerceptionMonthlySummary202111Mapper perceptionMonthlySummary202111Mapper;

    @Autowired
    private PerceptionTraining202111Mapper perceptionTraining202111Mapper;

    @Autowired
    private StudentAssessmentProgram202111Mapper studentAssessmentProgram202111Mapper;

    @Autowired
    private TrainingPerformanceFeedbackQuarter202111Mapper trainingPerformanceFeedbackQuarter202111Mapper;

    @Autowired
    private TrainingPerformanceFeedbackWeek202111Mapper trainingPerformanceFeedbackWeek202111Mapper;

    @Autowired
    private TrainingSensoryWeek202112 trainingSensoryWeek202112;

    @Autowired
    private GroupTrainingPlanSummaryWeek202112Mapper groupTrainingPlanSummaryWeek202112Mapper;


    @Override
    public CommonResult allTrainingInfo(BigInteger studentId, BigInteger classroomId, String tag, Integer ifAlone, BigInteger organizationId, BigInteger branchId, BigInteger employeeId, String keyword, String recordMonth, String recordYear, String lessonName, String studentName, int pageNum, int pageSize) {

        /*// 获取用户所有权限id
        List<Integer> resourceId = aloneClassMonthPlanAndSummaryMapper.getResourcesIdByRoleId(aloneClassMonthPlanAndSummaryMapper.getRoleId(employeeId));

        List<String> resource = new ArrayList<>();
        for (int id : resourceId) { // 添加所有权限
            resource.add(aloneClassMonthPlanAndSummaryMapper.getResourcesById(id));
        }*/
        List<Object> list = new ArrayList();
        StudentTrainingTable studentTrainingTable = new StudentTrainingTable();
        studentTrainingTable.setStudentName(studentName);
        studentTrainingTable.setOrganizationId(organizationId);
        studentTrainingTable.setBranchId(branchId);
        studentTrainingTable.setEmployeeId(employeeId);
        studentTrainingTable.setTag(tag);
        studentTrainingTable.setRecordMonth(recordMonth);
        studentTrainingTable.setRecordYear(recordYear);
        studentTrainingTable.setIfAlone(ifAlone);
        studentTrainingTable.setStudentId(studentId);
        studentTrainingTable.setClassroomId(classroomId);
        studentTrainingTable.setLessonName(lessonName);
        /*if ( resource.contains("orgAdmin:allStudentTrainingTable")) { // 机构的学生*/
        if (ifAlone == 0) {
            list.addAll(groupTrainingPlanSummaryMonth202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryWeek202112Mapper.allStudentTrainingInfo(studentTrainingTable));
        } else {
            list.addAll(aloneClassSummaryPhase202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(annualSummary202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(perceptionMonthlySummary202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(perceptionTraining202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(studentAssessmentProgram202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackQuarter202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackWeek202111Mapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(trainingSensoryWeek202112.allStudentTrainingInfo(studentTrainingTable));
        }

        /*list.addAll(aloneClassMonthPlanAndSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassMonthTeachingSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassMonthTeachingScheduleMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassRecordMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassSeasonPlanAndSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassSummaryPhaseMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassWeekFeedbackMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassWeekStudyReportMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassWeekTeachingScheduleMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(aloneClassWeekTeachingSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(groupTrainingPlanSummaryMonthMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(groupTrainingPlanSummaryPhaseMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(groupTrainingPlanSummaryWeekMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(perceptionTrainningMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(studentAssessmentProgramMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(trainingPerformanceFeedbackMonthMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(trainingPerformanceFeedbackQuarterMapper.allStudentTrainingInfo(studentTrainingTable));
        list.addAll(trainingPerformanceFeedbackWeekMapper.allStudentTrainingInfo(studentTrainingTable));*/
        Map<String, Object> map = new HashMap<>();
        map.put("total", list.size());
        map.put("data", hyqPageHelper(list, pageNum, pageSize));
        return CommonResult.success(map);
        /*} else if (resource.contains("branchAdmin:selfBranchStudentTrainingTable")) {// 自己分店的学生

            list.addAll(aloneClassMonthPlanAndSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassMonthTeachingSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassMonthTeachingScheduleMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassRecordMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassSeasonPlanAndSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassSummaryPhaseMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassWeekFeedbackMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassWeekStudyReportMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassWeekTeachingScheduleMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(aloneClassWeekTeachingSummaryMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryMonthMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryPhaseMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryWeekMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(perceptionTrainningMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(studentAssessmentProgramMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackMonthMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackQuarterMapper.allStudentTrainingInfo(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackWeekMapper.allStudentTrainingInfo(studentTrainingTable));
            return CommonResult.success(hyqPageHelper(list, pageNum, pageSize));
        } else if (resource.contains("teacherAdmin:selfStudentTrainingTable") && keyword.equals("")) {// 老师自己的学生

            // 得到自己学生列表
            String studentStr = aloneClassMonthPlanAndSummaryMapper.getStudentByTeacherId(studentTrainingTable);
            // 转换为数组
            String str[] = studentStr.split(",");

            for (String temp : str) {
                studentTrainingTable.setStudentId(BigInteger.valueOf(Long.parseLong(temp)));
                list.addAll(aloneClassMonthPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassMonthTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassMonthTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassRecordMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassSeasonPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassWeekFeedbackMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassWeekStudyReportMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassWeekTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(aloneClassWeekTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(groupTrainingPlanSummaryMonthMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(groupTrainingPlanSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(groupTrainingPlanSummaryWeekMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(perceptionTrainningMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(studentAssessmentProgramMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(trainingPerformanceFeedbackMonthMapper.selectByPrimaryKey(studentTrainingTable));
                list.addAll(trainingPerformanceFeedbackQuarterMapper.allStudentTrainingInfo(studentTrainingTable));
                list.addAll(trainingPerformanceFeedbackWeekMapper.selectByPrimaryKey(studentTrainingTable));

            }

            return CommonResult.success(hyqPageHelper(list, pageNum, pageSize));
        } else if (resource.contains("teamAdmin:selfTeamStudentTrainingTable") && keyword.equals("")) {// 自己教研组的所有学生

            // 得到自己学生列表
            List<String> studentStr = aloneClassMonthPlanAndSummaryMapper.getTeacherByTeamId(studentTrainingTable);
            List<BigInteger> studentList = new ArrayList<>();
            for (int i = 0; i < studentStr.size(); i++) {
                String[] str = studentStr.get(i).split(",");
                for (String temp : str) {
                    BigInteger id = BigInteger.valueOf(Long.parseLong(temp));
                    studentTrainingTable.setStudentId(id);
                    if (!studentList.contains(id)) {
                        studentList.add(id);
                        list.addAll(aloneClassMonthPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassMonthTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassMonthTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassRecordMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassSeasonPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekFeedbackMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekStudyReportMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(groupTrainingPlanSummaryMonthMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(groupTrainingPlanSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(groupTrainingPlanSummaryWeekMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(perceptionTrainningMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(studentAssessmentProgramMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(trainingPerformanceFeedbackMonthMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(trainingPerformanceFeedbackWeekMapper.selectByPrimaryKey(studentTrainingTable));
                    }
                }
            }
            return CommonResult.success(hyqPageHelper(list, pageNum, pageSize));
        }*/


        //return CommonResult.failed("查询失败，暂无数据！");
    }

    @Override
    public CommonResult getOneTeacherStudentTraining(String recordMonth, String recordYear,String tag, String keyword, BigInteger employeeId, int pageNum, int pageSize) {

        /*// 获取用户所有权限id
        List<Integer> resourceId = aloneClassMonthPlanAndSummaryMapper.getResourcesIdByRoleId(aloneClassMonthPlanAndSummaryMapper.getRoleId(employeeId));

        List<String> resource = new ArrayList<>();
        for (int id : resourceId) { // 添加所有权限
            resource.add(aloneClassMonthPlanAndSummaryMapper.getResourcesById(id));
        }
*/

        StudentTrainingTable studentTrainingTable = new StudentTrainingTable();
        studentTrainingTable.setEmployeeId(employeeId);
        studentTrainingTable.setStudentName(keyword);
        studentTrainingTable.setTag(tag);
        studentTrainingTable.setRecordYear(recordYear);
        studentTrainingTable.setRecordMonth(recordMonth);
        List<Object> list = new ArrayList();

        /*if (resource.contains("teamAdmin:selfTeamStudentTrainingTable") && keyword.equals("")) {// 自己教研组的所有学生
            // 得到自己学生列表
            List<String> studentStr = aloneClassMonthPlanAndSummaryMapper.getTeacherByTeamId(studentTrainingTable);

            List<BigInteger> studentList = new ArrayList<>();
            for (int i = 0; i < studentStr.size(); i++) {
                String[] str = studentStr.get(i).split(",");
                for (String temp : str) {
                    BigInteger id = BigInteger.valueOf(Long.parseLong(temp));
                    studentTrainingTable.setStudentId(id);
                    if (!studentList.contains(id)) {
                        studentList.add(id);
                        list.addAll(aloneClassMonthPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassMonthTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassMonthTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassRecordMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassSeasonPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekFeedbackMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekStudyReportMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(aloneClassWeekTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(groupTrainingPlanSummaryMonthMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(groupTrainingPlanSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(groupTrainingPlanSummaryWeekMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(perceptionTrainningMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(studentAssessmentProgramMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(trainingPerformanceFeedbackMonthMapper.selectByPrimaryKey(studentTrainingTable));
                        list.addAll(trainingPerformanceFeedbackWeekMapper.selectByPrimaryKey(studentTrainingTable));
                    }
                }
            }
        } else {*/  // 得到自己学生列表
        String studentStr = aloneClassMonthPlanAndSummaryMapper.getStudentByTeacherId(studentTrainingTable);
        System.out.println("自己教研组"+studentStr);
        // 转换为数组
        String[] str = studentStr.split(",");
        for (String temp : str) {
            studentTrainingTable.setStudentId(BigInteger.valueOf(Long.parseLong(temp)));
            list.addAll(aloneClassMonthPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassMonthTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassMonthTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassRecordMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassSeasonPlanAndSummaryMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassWeekFeedbackMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassWeekStudyReportMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassWeekTeachingScheduleMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(aloneClassWeekTeachingSummaryMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryMonthMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryPhaseMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(groupTrainingPlanSummaryWeekMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(perceptionTrainningMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(studentAssessmentProgramMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackMonthMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackQuarterMapper.selectByPrimaryKey(studentTrainingTable));
            list.addAll(trainingPerformanceFeedbackWeekMapper.selectByPrimaryKey(studentTrainingTable));
        }

        //}
        return CommonResult.success(hyqPageHelper(list, pageNum, pageSize));

    }


    @Override
    //@PermissionAnnotation
    public CommonResult addStudentTrainingTable(BigInteger employeeId, StudentTrainingTable studentTrainingTable, int ifAlone) {
        System.out.println(studentTrainingTable);
        if (aloneClassMonthPlanAndSummaryMapper.insertSelective(studentTrainingTable) == 1) {
            return CommonResult.success("新增成功！");
        }
        /*System.out.println(studentTrainingTable);
        if (tag.equals("个训课月教学计划与总结表")) {
            if (aloneClassMonthPlanAndSummaryMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课月教学计划表")) {
            if (aloneClassMonthTeachingScheduleMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课月教学总结表")) {
            if (aloneClassMonthTeachingSummaryMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课记录表")) {
            if (aloneClassRecordMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课季度教学计划与总结表")) {
            if (aloneClassSeasonPlanAndSummaryMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课阶段性学习总结")) {
            if (aloneClassSummaryPhaseMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课周反馈表")) {
            if (aloneClassWeekFeedbackMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课周学习报告")) {
            if (aloneClassWeekStudyReportMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课周教学计划表")) {
            if (aloneClassWeekTeachingScheduleMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("个训课周教学总结表")) {
            if (aloneClassWeekTeachingSummaryMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("集体训练月计划与总结表")) {
            if (groupTrainingPlanSummaryMonthMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("精准项目学生的集体课阶段性学习总结表")) {
            if (groupTrainingPlanSummaryPhaseMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("集体课周教学计划与总结表")) {
            if (groupTrainingPlanSummaryWeekMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("感统训练记录表")) {
            if (perceptionTrainningMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("月训练总结表")) {
            if (trainingPerformanceFeedbackMonthMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("海口雨润特殊儿童教育培训中心训练阶段计划与总结表")) {
            if (trainingPerformanceFeedbackQuarterMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        } else if (tag.equals("儿童周训练表现反馈记录表")) {
            if (trainingPerformanceFeedbackWeekMapper.insert(studentTrainingTable) == 1) {
                return CommonResult.success("新增成功！");
            }
            return CommonResult.failed("新增失败！");
        }*/
        return CommonResult.failed("失败");
    }

    @Override
    public CommonResult studentList(BigInteger employeeId, BigInteger organizationId, BigInteger branchId) {
        /*// 获取用户所有权限id
        List<Integer> resourceId = aloneClassMonthPlanAndSummaryMapper.getResourcesIdByRoleId(aloneClassMonthPlanAndSummaryMapper.getRoleId(employeeId));

        List<String> resource = new ArrayList<>();
        for (int id : resourceId) { // 添加所有权限
            resource.add(aloneClassMonthPlanAndSummaryMapper.getResourcesById(id));
        }*/

        //List<Object> list = new ArrayList();
        StudentTrainingTable studentTrainingTable = new StudentTrainingTable();
        studentTrainingTable.setEmployeeId(employeeId);
        studentTrainingTable.setOrganizationId(organizationId);
        studentTrainingTable.setBranchId(branchId);

        /*if ( resource.contains("orgAdmin:allStudentTrainingTable")) { // 机构的学生姓名
*/

        return CommonResult.success(aloneClassMonthPlanAndSummaryMapper.getStudentListByOrgOrBranch(studentTrainingTable));
        /*} else if (resource.contains("branchAdmin:selfBranchStudentTrainingTable")) {// 自己分店的学生
            return CommonResult.success(aloneClassMonthPlanAndSummaryMapper.getStudentListByOrgOrBranch(studentTrainingTable));
        } else if (resource.contains("teacherAdmin:selfStudentTrainingTable")) {// 老师自己的学生
            // 得到自己学生列表
            String studentStr = aloneClassMonthPlanAndSummaryMapper.getStudentByTeacherId(studentTrainingTable);
            // 转换为数组
            String[] str = studentStr.split(",");

            for (String temp : str) {
                studentTrainingTable.setStudentId(BigInteger.valueOf(Long.parseLong(temp)));
                list.add(aloneClassMonthPlanAndSummaryMapper.getStudentNameList(BigInteger.valueOf(Long.parseLong(temp))));

            }

            return CommonResult.success(list);
        } else if (resource.contains("teamAdmin:selfTeamStudentTrainingTable")) {// 自己教研组的所有学生

            // 得到自己学生列表
            List<String> studentStr = aloneClassMonthPlanAndSummaryMapper.getTeacherByTeamId(studentTrainingTable);

            List<BigInteger> studentList = new ArrayList<>();
            for (int i = 0; i < studentStr.size(); i++) {
                String str[] = studentStr.get(i).split(",");
                for (String temp : str) {
                    BigInteger id = BigInteger.valueOf(Long.parseLong(temp));
                    studentTrainingTable.setStudentId(id);
                    if (!studentList.contains(id)) {
                        studentList.add(id);
                        list.add(aloneClassMonthPlanAndSummaryMapper.getStudentNameList(id));
                    }
                }
            }
            return CommonResult.success(list);
        }
        return CommonResult.failed("查询失败，暂无数据！");*/
    }

    @Override
    public CommonResult getOneTrainingInfo(StudentTrainingTable studentTrainingTable) {
        String tag = studentTrainingTable.getTag();
        if (tag.equals("集体课周训练记录表")) {
            return CommonResult.success(groupTrainingPlanSummaryWeek202112Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("集体课月计划与总结表")) {
            return CommonResult.success(groupTrainingPlanSummaryMonth202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("感统训练记录表")) {
            return CommonResult.success(perceptionTraining202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("儿童康复季度阶段性学习总结表")) {
            return CommonResult.success(aloneClassSummaryPhase202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("海口雨润特殊儿童教育培训中心年度总结")) {
            return CommonResult.success(annualSummary202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("个训课月计划与总结表")) {
            return CommonResult.success(trainingPerformanceFeedbackQuarter202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("个训课周训练记录表")) {
            return CommonResult.success(trainingPerformanceFeedbackWeek202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("个训感统周训练记录表")) {
            return CommonResult.success(trainingSensoryWeek202112.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("评估计划报告表")) {
            return CommonResult.success(studentAssessmentProgram202111Mapper.getOneTrainingInfo(studentTrainingTable));
        } else if (tag.equals("个训感统月计划与总结表")) {
            return CommonResult.success(perceptionMonthlySummary202111Mapper.getOneTrainingInfo(studentTrainingTable));
        }
        return CommonResult.failed();
    }

    @Override
    //@PermissionAnnotation
    public CommonResult delTraining(BigInteger employeeId, StudentTrainingTable studentTrainingTable, int ifAlone) {
        System.out.println("进来");
        if (aloneClassMonthPlanAndSummaryMapper.delTraining(studentTrainingTable) == 1) {
            return CommonResult.success("删除成功!");
        }
        return CommonResult.failed("删除失败");
    }

    @Override
    //@PermissionAnnotation
    public CommonResult editTraining(BigInteger employeeId, StudentTrainingTable studentTrainingTable, int ifAlone) {
        studentTrainingTable.setUpdateTime(new Date());
        if (aloneClassMonthPlanAndSummaryMapper.editTraining(studentTrainingTable) == 1) {
            return CommonResult.success("修改成功！");
        }
        return CommonResult.failed("修改失败");
    }

    @Override
    public CommonResult getTeacherOption(StudentTrainingTable studentTrainingTable) {
        /*// 获取用户所有权限id
        List<Integer> resourceId = aloneClassMonthPlanAndSummaryMapper.getResourcesIdByRoleId(aloneClassMonthPlanAndSummaryMapper.getRoleId(studentTrainingTable.getEmployeeId()));

        List<String> resource = new ArrayList<>();
        for (int id : resourceId) { // 添加所有权限
            resource.add(aloneClassMonthPlanAndSummaryMapper.getResourcesById(id));
        }*/

        /*if ( resource.contains("orgAdmin:allTeacherInfo")) { // 机构的教师姓名*/
        return CommonResult.success(aloneClassMonthPlanAndSummaryMapper.getTeacherOption(studentTrainingTable));
        /*} else if (resource.contains("branchAdmin:selfBranchInfo")) {// 自己分店的教师

            return CommonResult.success(aloneClassMonthPlanAndSummaryMapper.getTeacherOption(studentTrainingTable));
        } else if (resource.contains("teamAdmin:selfTeamTeacherInfo")) {// 教研组自己的老师
            int teamId = aloneClassMonthPlanAndSummaryMapper.getTeamId(studentTrainingTable.getEmployeeId());
            studentTrainingTable.setTeamId(teamId);

            return CommonResult.success(aloneClassMonthPlanAndSummaryMapper.getTeacherOption(studentTrainingTable));
        }

        return CommonResult.failed("查询失败，暂无数据！");*/
    }

    public List<Object> hyqPageHelper(List<Object> list, int pageNum, int pageSize) {
        List<Object> temp = new ArrayList<>();

        for (int i = pageSize * (pageNum - 1); i < list.size() && i < (pageSize * (pageNum - 1) + pageSize); i++) {
            temp.add(list.get(i));
        }
        return temp;
    }


}
